package com.powernode.spring6.service;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component("logAspect")
@Aspect //
public class LogAspect {

//前置通知
    @Before("execution(* com.powernode.spring6.service.UserService.*(..))")
    public void 增强(){
        System.out.println("前置通知");

    }
    //
    @AfterReturning("execution(* com.powernode.spring6.service.UserService.*(..))")
    public void agterRunning(){
        System.out.println("后置通知");

    }
    //环绕通知是最大通知，在前置通知之前后置通知之后
    @Around("execution(* com.powernode.spring6.service.UserService.*(..))")
    public void  aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {

        System.out.println("前环绕");

        joinPoint.proceed(); //执行目标

        System.out.println("后环绕");
    }

    @AfterThrowing("execution(* com.powernode.spring6.service.UserService.*(..))")
    public void afterThrowing(){
        System.out.println();
    }

    @After("execution(* com.powernode.spring6.service.UserService.*(..))")
    public void AfterAdvice(){
        System.out.println("最终通知");
    }
}
